package chaowan.Mapper;

import chaowan.pojo.OrderMain;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface OrderMainMapper {
    @Select("SELECT * FROM order_main")
    List<OrderMain> selectAll();


    @Select("SELECT * FROM order_main WHERE oid = #{oid}")
    OrderMain selectById(Long oid);

    @Insert("INSERT INTO order_main(uid, total, status, receive_info, created) " +
            "VALUES(#{uid}, #{total}, #{status}, #{receiveInfo}, #{created})")
    @Options(useGeneratedKeys = true, keyProperty = "oid")
    int insert(OrderMain orderMain);

    @Update("UPDATE order_main SET uid=#{uid}, total=#{total}, status=#{status}, receive_info=#{receiveInfo}, created=#{created} WHERE oid=#{oid}")
    int update(OrderMain orderMain);

    @Delete("DELETE FROM order_main WHERE oid = #{oid}")
    int deleteById(Long oid);

    @Select("SELECT COUNT(*) FROM order_main WHERE uid = #{uid}")
    int countByUserId(@Param("uid") Integer uid);

    @Select("SELECT * FROM order_main WHERE uid = #{uid} ORDER BY created DESC")
    List<OrderMain> findByUserId(@Param("uid") Long uid);
}